<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
$chk->checkShow3dPage();
if (!in_array($chk->show3D3S, array(1, 2)))
{
    exit("error show3D3S");
}
unset($chk);
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
$timePre2Mon = date("Y-m-d", strtotime("-1 month"));
$actionMsg1 = "";
$actionMsg2 = "";
$open2 = "";
$useTypechecked = 1;
if (ispost())
{
    include_once( "class/function_3d.php" );
    include_once( "class_3d/Amounts_float_3d.php" );
    $Amounts_float_3d = new Amounts_float_3d();
    $calcType = intval(getvar("calcType"));
    if ($calcType == 1)
    {
        $paperOpen = getvar("open1");
        if (!is_date($paperOpen))
        {
            $actionMsg1 = "<div style=\"text-align:center;font-weight:bold;color:yellow;background-color:red\">错误的日期格式！</div>";
            $timePre2Mon = "";
        }
        else
        {
            $delNum = $Amounts_float_3d->calcClearData($paperOpen, 3);
            $actionMsg1 = "<div style=\"text-align:center;font-weight:bold;color:red;background-color:yellow\">报表日 {$paperOpen} (含)，合值为零之浮动资料清除成功！(共 {$delNum} 笔)</div>";
            $timePre2Mon = $paperOpen;
        }
    }
    else if ($calcType == 2)
    {
        $paperOpen = getvar("open2");
        if (!is_date($paperOpen))
        {
            $actionMsg2 = "<div style=\"text-align:center;font-weight:bold;color:yellow;background-color:red\">错误的日期格式！</div>";
        }
        else
        {
            $nowTime = date("Y-m-d H:i:s");
            $sql = " SELECT id FROM lotto_3s1 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_3s2 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_3s3 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_3s4 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_3s5 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_3s6 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_5h WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_8h WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_8h2 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $sql .= " UNION ALL ";
            $sql .= " SELECT id FROM lotto_8h3 WHERE open = '{$paperOpen}' AND openbet > '{$nowTime}' LIMIT 1";
            $rs = getdb($sql);
            if ($rs->eof)
            {
                $useType = intval(getvar("useType"));
                switch ($useType)
                {
                    case 1 :
                        $old_cal_3s1 = $conf->get("systemcheck_3s1");
                        $old_cal_3s2 = $conf->get("systemcheck_3s2");
                        $old_cal_3s3 = $conf->get("systemcheck_3s3");
                        $old_cal_3s4 = $conf->get("systemcheck_3s4");
                        $old_cal_3s5 = $conf->get("systemcheck_3s5");
                        $old_cal_3s6 = $conf->get("systemcheck_3s6");
                        $old_cal_5h = $conf->get("systemcheck_5h");
                        $old_cal_8h = $conf->get("systemcheck_8h");
                        $old_cal_8h2 = $conf->get("systemcheck_8h2");
                        $old_cal_8h3 = $conf->get("systemcheck_8h3");
                        if ($old_cal_3s1 == 0)
                        {
                            $conf->set("systemcheck_3s1", 1);
                        }
                        if ($old_cal_3s2 == 0)
                        {
                            $conf->set("systemcheck_3s2", 1);
                        }
                        if ($old_cal_3s3 == 0)
                        {
                            $conf->set("systemcheck_3s3", 1);
                        }
                        if ($old_cal_3s4 == 0)
                        {
                            $conf->set("systemcheck_3s4", 1);
                        }
                        if ($old_cal_3s5 == 0)
                        {
                            $conf->set("systemcheck_3s5", 1);
                        }
                        if ($old_cal_3s6 == 0)
                        {
                            $conf->set("systemcheck_3s6", 1);
                        }
                        if ($old_cal_5h == 0)
                        {
                            $conf->set("systemcheck_5h", 1);
                        }
                        if ($old_cal_8h == 0)
                        {
                            $conf->set("systemcheck_8h", 1);
                        }
                        if ($old_cal_8h2 == 0)
                        {
                            $conf->set("systemcheck_8h2", 1);
                        }
                        if ($old_cal_8h3 == 0)
                        {
                            $conf->set("systemcheck_8h3", 1);
                        }
                        $Amounts_float_3d->countBetAgain($paperOpen, "x");
                        if ($old_cal_3s1 == 0)
                        {
                            $conf->set("systemcheck_3s1", 0);
                        }
                        if ($old_cal_3s2 == 0)
                        {
                            $conf->set("systemcheck_3s2", 0);
                        }
                        if ($old_cal_3s3 == 0)
                        {
                            $conf->set("systemcheck_3s3", 0);
                        }
                        if ($old_cal_3s4 == 0)
                        {
                            $conf->set("systemcheck_3s4", 0);
                        }
                        if ($old_cal_3s5 == 0)
                        {
                            $conf->set("systemcheck_3s5", 0);
                        }
                        if ($old_cal_3s6 == 0)
                        {
                            $conf->set("systemcheck_3s6", 0);
                        }
                        if ($old_cal_5h == 0)
                        {
                            $conf->set("systemcheck_5h", 0);
                        }
                        if ($old_cal_8h == 0)
                        {
                            $conf->set("systemcheck_8h", 0);
                        }
                        if ($old_cal_8h2 == 0)
                        {
                            $conf->set("systemcheck_8h2", 0);
                        }
                        if ($old_cal_8h3 == 0)
                        {
                            $conf->set("systemcheck_8h3", 0);
                        }
                        $useTypechecked = 1;
                        $actionMsg2 = "<div style=\"text-align:center;font-weight:bold;color:red;background-color:yellow\">报表日 {$paperOpen} 结算浮动额度成功！</div>";
                        break;
                    case 2 :
                        $Amounts_float_3d->countBet("", "", $paperOpen, "x");
                        $useTypechecked = 2;
                        $actionMsg2 = "<div style=\"text-align:center;font-weight:bold;color:red;background-color:yellow\">报表日 {$paperOpen} 结算浮动额度成功！</div>";
                        break;
                }
                $open2 = $paperOpen;
            }
            else
            {
                $actionMsg2 = "<div style=\"text-align:center;font-weight:bold;color:yellow;background-color:red\">报表日 {$paperOpen}，尚有期数开盘中，无法结算</div>";
            }
        }
    }
}
$tpl->load("main", "calcAmountsFloat_3d.htm");
$tpl->set(array("action" => "op.php?op=admin&fp=calcAmountsFloat_3d&gametype={$gametype}", "open1" => $timePre2Mon, "open2" => $open2, "actionMsg1" => $actionMsg1, "actionMsg2" => $actionMsg2, "checked", "gametype" => $gametype));
$ui->header();
include( "admin_menu_3d.php" );
$ui->load("calendar_js", "calendar_js.htm");
$ui->show("calendar_js");
$tpl->show("main");
$ui->footer();
?>